using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using ShopForWeb.UI.Utils.Extensions;

namespace ShopForWeb.UI.Utils.Filters
{
    public class UserInfoAttribute : Attribute, IResultFilter
    {
        public void OnResultExecuted(ResultExecutedContext context)
        {
            
        }

        public void OnResultExecuting(ResultExecutingContext context)
        {
            Controller  controller=(Controller)context.Controller;
            var request=controller.HttpContext.Request;
            if(request.Headers["X-Requested-With"]=="XMLHttpRequest")
            return;
            controller.ViewBag.User=controller.GetUser();
        }
    }
}